import { post } from "./request/request";
import apiUrl from "./urls";
import { getToken, clearLocalToken } from "./userInfo";
import { Storage } from "./tools/public";

import key from "./storageKeyMap";

const IMtoken = Storage.getSync(key.IMTOKEN) || "";

async function heartbeatSend() {
  // 防止未登录状态下积累过多请求
  if (!getToken()) return;
  if (!IMtoken) return;
  await post(apiUrl.heartbeat, {},{
    silentFail: true,
    showLoading: false,
  });
}

const heartbeatDelay = 200000;

function runHeartbeatSend() {
  heartbeatSend();
  setTimeout(runHeartbeatSend, heartbeatDelay);
}

export { runHeartbeatSend };
